<template>
  <div class="titleToolBar">
    <div class="fold" v-if="item.fold" @click="fold">
      <i :class="foldClass"></i>
      <span class="label">{{ item.label }}</span>
    </div>
    <div class="title" v-else>{{ item.label }}</div>
    <div class="toolBar">
      <template v-for="(btn, index) in item.buttons">
        <el-button
          v-if="btn.show"
          size="medium"
          :type="btn.type || 'default'"
          :key="index"
          :class="btn.class"
          @click="
            () => {
              buttonFuc(btn);
            }
          "
          :accesskey="btn.accesskey"
        >
          {{ btn.label }}
        </el-button>
      </template>
    </div>
  </div>
</template>

<script>
export default {
  name: "titleToolBar",
  props: {
    item: {
      type: Object,
      default: () => {
        return {};
      }
    },
    formData: {
      type: Object,
      default: () => {
        return {};
      }
    }
  },
  data() {
    return {
      isFold: false
    };
  },
  methods: {
    buttonFuc(button) {
      button.func(this.formData);
    },
    fold() {
      this.isFold = !this.isFold;
      this.$emit("fold");
    }
  },
  computed: {
    foldClass: function() {
      return this.isFold
        ? "iconfont iconicon-list-add"
        : "iconfont iconicon-list-less";
    }
  }
};
</script>

<style scoped lang="scss">
.titleToolBar {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 0 32px;

  .fold {
    height: 30px;
    color: #1b65b9;
    cursor: pointer;

    i {
      text-align: left;
    }

    .label {
      font-size: 13px;
      font-weight: bold;
    }
  }

  .title {
    margin-left: 7px;
    font-size: 16px;
    font-weight: bold;
    font-family: "Microsoft YaHei", "微软雅黑", Arial, sans-serif,
      "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB";
    margin-bottom: 15px;
    display: inline-block;
    vertical-align: top;
    line-height: 16px;
  }

  .title:before {
    content: "";
    border-left: 6px solid #1b65b9;
    height: 16px;
    margin-right: 4px;
    display: inline-block;
    vertical-align: top;
  }

  .toolBar {
    margin-bottom: 15px;
  }
}
</style>
